#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int n, m, q, k;
int a[N], c[N];

void fre()
{
	freopen("arena.in", "r", stdin);
	freopen("arena.out", "w", stdout);
}

int main()
{
	fre();
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ )
		cin >> a[i];
	for (int i = 1; i <= m; i ++ )
		cin >> c[m];
		
	int q = n;
	while (q)
	{
		q /= 2;
		k ++ ;
	}

	for (int i = 1; i <= k; i ++ )
	{
		string s;
		cin >> s;
	}

	int T; cin >> T;
	while (T -- )
	{
		int tt[4];
		for (int i = 0; i < 4; i ++ )
			cin >> tt[i];
		cout << 1 << endl;
	}
	return 0;
}
